<?php
namespace app\back\controller;

use \app\common\libs\WeixinHelper;
class Setting extends \app\common\controller\BaseController
{   

    public function index() {

    	return $this->fetch('');
    }

    /*
	 * 创建微信公众号自定义菜单
     */
    public function createSelfMenu() {
    	$config_model = new \app\common\model\Config;
    	$json_data = $config_model->getSelfMenu();

        if(request()->isPost()) {
        	$res = WeixinHelper::customOrder($json_data, \token());

        	$this->success($res['errmsg'], url('back/setting/index'), '', 3);
        }

        return $this->fetch('create_self_menu', ['json_data'=>var_export(json_decode($json_data, true), true)]);
    }

    /*
     * 取消自定义菜单cmd
     */
    public function cancelSelfMenu() {
        $res = WeixinHelper::cancelCustomOrder(\token());
        $this->success($res['errmsg'], url('back/setting/index'), '', 3);
    }
}
